package com.example.springboot.druid.web;

import com.example.springboot.druid.entity.User;
import com.example.springboot.druid.service.UserService;
import com.example.springboot.druid.util.UUIDUtil;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
* @desc mybatis 操作数据库查询示例
* @Author wangsh
* @date 2018/5/6 12:11
* @return 
*/
@RestController
@RequestMapping("/user")
public class UserController {
	/**
	 * 通过mybatis xml配置文件读取数据
	 */
	@Autowired
	private UserService userService;

	@RequestMapping("/getUserById")
	@ResponseBody
	public User getUserById(String id) {
		User User = userService.getUserById(id);
		return User;
	}

	@RequestMapping("/queryList")
	@ResponseBody
	public List<User> queryList() {
		// 设置分页
		PageHelper.startPage(1, 2);
		List<User> queryList = userService.queryList();
		return queryList;
	}

	@RequestMapping("/save")
	@ResponseBody
	public User save() {
		User user = new User();
		user.setId(UUIDUtil.getUUID());
		user.setUsername("lisi");
		user.setPassword("lisi");
		userService.save(user);
		return user;
	}
}
